import time

import win32clipboard
from ctypes import *


# 复制任意类型的文件到剪切板 按crtl+v 可粘贴出来
class DROPFILES(Structure):
    _fields_ = [
        ("pFiles", c_uint),
        ("x", c_long),
        ("y", c_long),
        ("fNC", c_int),
        ("fWide", c_bool),
    ]


pDropFiles = DROPFILES()
pDropFiles.pFiles = sizeof(DROPFILES)
pDropFiles.fWide = True
matedata = bytes(pDropFiles)


def setClipboardFiles(paths):
    files = ("\0".join(paths)).replace("/", "\\")
    data = files.encode("U16")[2:] + b"\0\0"
    win32clipboard.OpenClipboard()
    # 清空剪贴板
    win32clipboard.EmptyClipboard()
    try:
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardData(
            win32clipboard.CF_HDROP, matedata + data)
    finally:
        win32clipboard.CloseClipboard()


# 复制单个文件到剪切板,传入文件路径即可
def setClipboardFile(file):
    setClipboardFiles([file])
    time.sleep(0.5)
